package com.netty.chatRoom.server.config;

import com.netty.chatRoom.server.serializer.Serializer;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Config {
    static Properties properties;
    static {
        try (InputStream in= Config.class.getResourceAsStream("/application.properties")){
            properties=new Properties();
            properties.load(in);
        } catch (IOException e) {
            throw new ExceptionInInitializerError();
        }
    }
    public static int getServerPort(){
        String value= properties.getProperty("server.port");
        if (value==null){
            return 8080;
        }else {
            return Integer.parseInt(value);
        }
    }

    public static Serializer.Algorithm getSerializerAlgorithm(){
        String value= properties.getProperty("serializer.algorithm");
        if (value==null){
            return Serializer.Algorithm.JAVA;
        }else {
            return Serializer.Algorithm.valueOf(value);
        }
    }
}
